<?php

use yii\db\Migration;

/**
 * Handles adding columns to table `{{%contract}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%contract_purchase_method}}`
 */
class m221113_111804_add_id_purchase_method_column_to_contract_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->addColumn('{{%contract}}', 'id_purchase_method', $this->integer());

        // creates index for column `id_purchase_method`
        $this->createIndex(
            '{{%idx-contract-id_purchase_method}}',
            '{{%contract}}',
            'id_purchase_method'
        );

        // add foreign key for table `{{%contract_purchase_method}}`
        $this->addForeignKey(
            '{{%fk-contract-id_purchase_method}}',
            '{{%contract}}',
            'id_purchase_method',
            '{{%contract_purchase_method}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%contract_purchase_method}}`
        $this->dropForeignKey(
            '{{%fk-contract-id_purchase_method}}',
            '{{%contract}}'
        );

        // drops index for column `id_purchase_method`
        $this->dropIndex(
            '{{%idx-contract-id_purchase_method}}',
            '{{%contract}}'
        );

        $this->dropColumn('{{%contract}}', 'id_purchase_method');
    }
}
